#ifndef _OBJECT3D_H_
#define _OBJECT3D_H_

#include "engine.h"

namespace engine
{

    class Object3D
    {
    public:
        typedef std::shared_ptr<Object3D> ptr;

    public:
        Object3D()
            : Position(glm::vec3(0.0f, 0.0f, 0.0f)), Rotate(glm::vec3(0.0f, 0.0f, 0.0f)), Scale(glm::vec3(1.0f, 1.0f, 1.0f))
        {
        }

        ~Object3D() {}
        /**
         * 添加子对象
         */
        void addChildren(Object3D *object)
        {
            this->mChildren.push_back(object);
        }

        void setPosition(float x, float y, float z)
        {
            this->Position.x = x;
            this->Position.y = y;
            this->Position.z = z;
        }

        void setRotate(float x, float y, float z)
        {
            this->Rotate.x = x;
            this->Rotate.y = y;
            this->Rotate.z = z;
        }

        void setScale(float x, float y, float z)
        {
            this->Scale.x = x;
            this->Scale.y = y;
            this->Scale.z = z;
        }

        void move(float x, float y, float z)
        {
            this->Position.x += x;
            this->Position.y += y;
            this->Position.z += z;
        }

        void rotate(float x, float y, float z)
        {
            this->Rotate.x = cos(glm::radians(z)) * cos(glm::radians(x));
            this->Rotate.y = sin(glm::radians(x));
            this->Rotate.z = sin(glm::radians(z)) * cos(glm::radians(x));
        }

        void scale(float x, float y, float z)
        {
            this->Scale.x = x;
            this->Scale.y = y;
            this->Scale.z = z;
        }

        Object3D *getChildrenByName(const char *name)
        {
            for (int i = 0; i < this->mChildren.size(); i++)
            {
                if (mChildren[i]->name == name)
                {
                    return mChildren[i];
                }
            }
            return NULL;
        }

        glm::mat4 getTransformMatrix()
        {
            glm::mat4 trans = glm::mat4(1.0f); //单位阵
            trans = glm::translate(trans, this->Position);
            trans = glm::rotate(trans, glm::radians(this->Rotate.x), glm::vec3(1.0, 0.0, 0.0)); //x
            trans = glm::rotate(trans, glm::radians(this->Rotate.y), glm::vec3(0.0, 1.0, 0.0)); //y
            trans = glm::rotate(trans, glm::radians(this->Rotate.z), glm::vec3(0.0, 0.0, 1.0)); //z
            // trans = glm::rotate(trans, this->rotate);
            trans = glm::scale(trans, this->Scale);
            return trans;
        }

    public:
        std::string name;
        std::vector<Object3D *> mChildren;
        glm::vec3 Position;
        glm::vec3 Rotate;
        glm::vec3 Scale;

    protected:
        
    };

}
#endif